var crud = require('../../util/crud');
var model = require('../../model/index.js');
var TeacherSchedule = model.get('TeacherSchedule');
var response = require('../../util/response');
var modules = {};

modules.create = (req, res) => {
   
    TeacherSchedule.create(req.body).then((teacherSchedule) => {

    	return res.json(response.success({data: teacherSchedule}))
    }).catch(err => {
        console.log('teacherSchedule create err, err = ' + err);
        return res.json(response.error('新建教师课程表失败')).end();
    })
}
modules.find = (req, res) => {
    const query = req.query,
        filter = query.filter || {};
    
    TeacherSchedule.find(filter).then((teacherSchedules) => {

    	return res.json(response.success({data: teacherSchedules}))
    }).catch(err => {
        console.log('teacherSchedules find err, err = ' + err);
        return res.json(response.error('查找老师课程表失败')).end();
    })
}
modules.update = (req, res) => {
    const filter = req.query;
    const update = req.body;

    TeacherSchedule.update(filter, update).then((teacherSchedule) => {
    	return res.json(response.success({message: '更新老师课程表成功', data: teacherSchedule}))
    }).catch(err => {
        console.log('teacherSchedule update err, err = ' + err);
        return res.json(response.error('更新老师课程表失败')).end();
    })
}
modules.remove = (req, res) => {
    const filter = req.query;

    TeacherSchedule.remove(filter).then((result) => {
    	return res.json(response.success({message: '删除老师课程表成功'}))
    }).catch(err => {
        console.log('teacherSchedule remove err, err = ' + err);
        return res.json(response.error('删除老师课程表失败')).end();
    })
}

module.exports = (router) => {
    crud(router, modules);
}